<template>
	<view class="view">
		<view class="class">
			<view class="good" v-for="(item,index) in list" :key="index">
				<!-- <view>订单类型：{{item.logisticsOrderNum}}</view> -->
				<view>实际支付金额：{{item.amount}}</view>
				<view>订单号：{{item.orderNo}}</view>
				<view>创建时间：{{create[index]}}</view>
				<view>
					<view class="time" v-if='countdownd[index]>0'>
						剩余认养时间：<view class="shijian">{{countdownd[index]}}</view>天
					</view>
				</view>
				<view class="green" v-if="item.isDeleted==0">已生效</view>
				<view class="red" v-else>已失效</view>
			</view>
		</view>

	</view>
</template>
<script>
	export default {
		data() {
			return {
				list: [],
				create: [],
				end: [],
				countdownd: [],
				timer: null, //重复执行,
				ID: '',
			}
		},
		methods: {
			//开始时间
			dateArrayTransfer(dateArray) {
				if (dateArray == null || dateArray == '') {
					return '';
				}
				var returnDate = dateArray[0] + "-" +
					this.returnDoubleNum(dateArray[1]) + "-" +
					this.returnDoubleNum(dateArray[2])
				return returnDate;
			},
			//结束时间
			dateArrayTransfer1(dateArray) {
				if (dateArray == null || dateArray == '') {
					return '';
				}
				var returnDate = dateArray[0] + 1 + "-" +
					this.returnDoubleNum(dateArray[1]) + "-" +
					this.returnDoubleNum(dateArray[2])
				return returnDate;
			},
			returnDoubleNum(number) {
				return (Array(2).join(0) + number).slice(-2); //创建一个长度为2的数组，且默认用0填充；然后用传过来的数添加都右边，然后从右向左截取两位！
			},
			showtime(endtime) {
				var nowtime = new Date(), //获取当前时间
					endtime = new Date(endtime); //定义结束时间
				var lefttime = endtime.getTime() - nowtime.getTime(), //距离结束时间的毫秒数
					leftd = Math.floor(lefttime / (1000 * 60 * 60 * 24)); //计算天数
				if (leftd <= 0) {

				}
				this.countdownd.push(leftd)
			}
		},
		created() {
			this.$http({
				url: '/mySon',
				method: 'get',
				data: {
					id: this.ID
				}
			}).then(res => {
				for (var i = 0; i < res.data.data.length; i++) {
					if (res.data.data[i].payType == 5 && res.data.data[i].payStatus == 1) {
						this.list.push(res.data.data[i])
						this.create.push(this.dateArrayTransfer(res.data.data[i].createTime))
						this.end.push(this.dateArrayTransfer1(res.data.data[i].createTime))
					}
				}
			})
		},
		onLoad(options) {
			this.ID = options.ID
			this.timer = setTimeout(() => {
				for (var i = 0; i < this.end.length; i++) {
					this.showtime(this.end[i])
				}
			}, 1000)
		},
	}
</script>

<style lang="scss">
	@import './index.css';
</style>
